/**
 * Created by wry on 2015/1/23.
 */
var toolUtil = require('../common/utils/toolUtil');
var messageUtil = require('../common/utils/messageUtil');

exports.md5Validate = function (req, res, next) {

    if (enbaleMd5 == 'Yes') {
        //if (req.url.indexOf('/rest/' + RESTFullServiceVersion + '/users/signup') == 0
        //    || req.url.indexOf('/rest/' + RESTFullServiceVersion + '/users/appLogin/') == 0
        //    || req.url.indexOf('/rest/' + RESTFullServiceVersion + '/users/login/') == 0) {
        var tempArray = req.url.split('/');
        var deviceId = tempArray[tempArray.length - 1];
        var input = req.body;
        if (input == null) {
            next();
        } else {
            var result = toolUtil.md5Validate(deviceId, input);
            if (result) {
                next();
            } else {
                res.json(messageUtil.composeFailedMessage('请求错误'));
            }
        }
        //} else {
        //    next();
        //}
    } else {
        next();
    }
};